<?php
/**
 * Created by PhpStorm.
 * User: kcswag
 * Date: 12/9/17
 * Time: 3:57 PM
 */

namespace AppBundle\Libs;


use AppBundle\Entity\Borrowers;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\DependencyInjection\Container;

class Payment
{
    private $container;

    private $list = [];

    private $paymentCompany;

    public function __construct(Container $container, PaymentCompany $company)
    {
        $this->container = $container;
        $this->paymentCompany = $company;
    }


    public function getList(){
        if(!empty($this->list)){
            return $this->list;
        }else{
            $this->list = $this->container->getParameter('payment')['payment_list'];
            return $this->list;
        }
    }

    public function getDefaultPaymentCompany(){
        return $this->paymentCompany;
    }


    public function choose($paymentCompanyName){
        $list = $this->getList();

        if(!in_array($paymentCompanyName,$list)){
            throw new Exception("Invalid payment company {$paymentCompanyName} !",'200');
        }

        $this->paymentCompany->setName($paymentCompanyName);
    }

    public function pay(Borrowers $borrower){

    }

}